package
{
	import flash.display.BitmapData;
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.geom.Rectangle;
	import flash.net.URLVariables;
	import flash.utils.ByteArray;
	
	public class CommonResource
	{
		public static var mvDialog:ByteArray
		public static var myAvatar:BitmapData;
		public static var myPlayer:Player;
		public static var myUIMenu:MovieClip;
		public static var myCharPanel:MovieClip;
		public static var host:String = "http://aagntw29.facebook.joyent.us/game/";
		public static var terrainList:Vector.<Terrain> = new Vector.<Terrain>();
		public static var objectsList:Vector.<MapObject> = new Vector.<MapObject>();
		public function CommonResource()
		{
		}

		
		/**
		 * duplicateDisplayObject
		 * creates a duplicate of the DisplayObject passed.
		 * similar to duplicateMovieClip in AVM1
		 * @param target the display object to duplicate
		 * @param autoAdd if true, adds the duplicate to the display list
		 * in which target was located
		 * @return a duplicate instance of target
		 */
		public static function duplicateDisplayObject(target:DisplayObject, autoAdd:Boolean = false):DisplayObject {
			// create duplicate (constructor in quotes to bypass strict mode)
			var targetClass:Class = target["constructor"];
			var duplicate:DisplayObject = new targetClass();
			
			// duplicate properties
			duplicate.transform = target.transform;
			duplicate.filters = target.filters;
			duplicate.cacheAsBitmap = target.cacheAsBitmap;
			duplicate.opaqueBackground = target.opaqueBackground;
			if (target.scale9Grid) {
				var rect:Rectangle = target.scale9Grid;
				// Flash 9 bug where returned scale9Grid is 20x larger than assigned
				rect.x /= 20, rect.y /= 20, rect.width /= 20, rect.height /= 20;
				duplicate.scale9Grid = rect;
			}
			
			// add to target parent's display list
			// if autoAdd was provided as true
			if (autoAdd && target.parent) {
				target.parent.addChild(duplicate);
			}
			return duplicate;
		}
		public static function clone(source:Object):*
		{
			var myBA:ByteArray = new ByteArray();
			myBA.writeObject(source);
			myBA.position = 0;
			return(myBA.readObject());
		}
		public static function SetPlayerData():void
		{
			var vars:URLVariables = new URLVariables();
			
			vars.ulevel = 9;
			switch(myPlayer.classID)
			{
				case 1:
					vars.className = "Knight";
					break;
				case 2:
					vars.className = "Necromancer";
					break;
				case 3:
					vars.className = "Wizard";
					break;
			}
			
			vars.attackBase = 5;
			vars.defenseBase = 5;
			vars.spellpowerBase = 5;
			vars.knowledgeBase = 5;
			
			vars.attackCurrent = 4;
			vars.defenseCurrent = 6;
			vars.spellpowerCurrent = 5;
			vars.knowledgeCurrent = 5;
			
			vars.point = 3;
			
			myCharPanel.SetUser(vars);
		}
	}
}